import Vue from 'vue'
import Router from 'vue-router'
import {loadroot} from '@/utils/menuUtil'
Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import portal from '@/views/portal/index1'

export const constantRoutes = []
const _asyncRoutes = []
export const asyncRoutes = _asyncRoutes.concat()
  export const defaultRoutes = [{
      path: '/login',
      component: () => import('@/views/login/index'),
      hidden: true
    }, {
      path: '/auth-redirect',
      component: () => import('@/views/login/auth-redirect'),
      hidden: true
    }, {
      path: '/404',
      component: () => import('@/views/error-page/404'),
      hidden: true
    }, {
      path: '/401',
      component: () => import('@/views/error-page/401'),
      hidden: true
    }, {
      path: '/',
      redirect: '/layout/index',
      hidden: true
    }, {
      path: '/portal',
      // redirect: '/portal',
      component: portal,
      hidden: true
    },
    {
      path:'/layout',
      component: Layout,
      redirect: '/layout/index',
      hidden: true,
      children: [{
          path: 'index',
          component: () => import('@/mainLayout/orgmanager/index'),
          name: 'main',
          meta: {
            title: 'main',
            icon: 'home',
            affix: true
          },

        }
      ]
    },
     {
      path: '/mainLayout',
      component: Layout,
      redirect: '/mainLayout/index',
      hidden: true,
      children: [{
          path: 'index',
          component: () => import('@/mainLayout/orgmanager/index'),
          name: 'mainLayout',
          meta: {
            title: '',
            icon: 'home',
            affix: true
          },

        }
      ],
    }
  ]

//loadroot(defaultRoutes)
const createRouter = () => {
  return new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({
      y: 0
    }),
    routes: defaultRoutes
  })
}

const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router
